package com.demo.apparel.mapper.uniapp;

import com.demo.apparel.dto.uniapp.WxFeedbackDTO;
import com.demo.apparel.entity.Feedback;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface WxFeedbackMapper {

    @Insert("""
        INSERT INTO feedback (id, user_id, content, contact, status, created_time, updated_time)
        VALUES (#{id}, #{userId}, #{content}, #{contact}, #{status}, #{createdTime}, #{updatedTime})
    """)
    int insert(Feedback feedback);

    @Select("SELECT * FROM feedback WHERE user_id = #{userId} ORDER BY created_time DESC LIMIT #{offset}, #{limit}")
    @Results(id = "FeedbackDTOMap", value = {
            @Result(column = "id", property = "id"),
            @Result(column = "user_id", property = "userId"),
            @Result(column = "content", property = "content"),
            @Result(column = "contact", property = "contact"),
            @Result(column = "status", property = "status"),
            @Result(column = "created_time", property = "createdTime"),
            @Result(column = "updated_time", property = "updatedTime")
    })
    List<WxFeedbackDTO> selectByUserId(@Param("userId") String userId,
                                       @Param("offset") int offset,
                                       @Param("limit") int limit);

    @Select("SELECT COUNT(*) FROM feedback WHERE user_id = #{userId}")
    long countByUserId(@Param("userId") String userId);

    /**
     *
     * @param id
     * @return
     */
    @Select("SELECT * FROM feedback WHERE id = #{id}")
    @ResultMap("FeedbackDTOMap")
    WxFeedbackDTO selectById(@Param("id") String id);

}
